package utils{
	import events.GameEvent;
	
	import flash.display.InteractiveObject;
	import flash.display.Loader;
	import flash.display.LoaderInfo;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.net.URLRequest;
	
	public class SwfElements extends Sprite{
		private var lib_swf:LoaderInfo;
		public var isComplete:Boolean;
		private var _mcName:String;
		public function SwfElements(){
			var loader:Loader=new Loader();
			var request:URLRequest=new URLRequest();
			request.url="assets/kingdomRush.swf";
			loader.contentLoaderInfo.addEventListener(Event.COMPLETE,swfCompleteHandler);
			loader.load(request);
		}
		
		private function swfCompleteHandler(event:Event):void{
			lib_swf=event.target as LoaderInfo;
			isComplete = true;
			var evt:Event = new GameEvent(GameEvent.SWF_LOADER_COMPLETE);
			this.dispatchEvent(evt);
		}
		
		public function getMC(_name:String):MovieClip{
			var cla:Class = lib_swf.applicationDomain.getDefinition(_name) as Class;
			var mc:InteractiveObject = new cla() as InteractiveObject;
			return mc as MovieClip;
		}
		
	}
}